package dynamic.dpPack;

import java.util.Arrays;

/**
 * 加了体积、重量的二维背包
 */
public class TwoDPack {

    private int packTwoDp(int V, int W, int[] value, int[] volume, int[] weight) {
        int[][] dp = new int[V+1][W+1];  // V体积 W重量
        for (int i=1; i<=value.length; i++) {
            for (int j=V; j>=volume[i-1]; j--) {
                for (int k=W; k>=weight[i-1]; k--) {
                    dp[j][k] = Math.max(dp[j][k], dp[j-volume[i-1]][k-weight[i-1]]+value[i-1]);
                }
            }
            System.out.println(Arrays.toString(dp[i]));
        }
        return dp[V][W];
    }

    public static void main(String[] args) {
        int[] value = new int[]{3, 4, 5, 6};
        int[] volume = new int[]{1, 2, 3, 4};
        int[] weight = new int[]{2, 4, 4, 5};
        int V = 5;
        int W = 6;
        TwoDPack twoDPack = new TwoDPack();
        int ans = twoDPack.packTwoDp(V, W, value, volume, weight);
        System.out.println("dp ans:"+ans);
    }
}
